package com.tedu.day01.oop;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class ColorJPanel extends JPanel implements  Runnable{
	
	int time;
	Thread t;
	public ColorJPanel() {		
		setBackground(Color.BLACK);
		t=new Thread(this);
		t.start();
		
	}
	public void paint(Graphics g){
		super.paint(g);
	}
	@Override
	public void run() {
		while(true){
			time++;
			if(time==10){
				setBackground(Color.YELLOW);}
			else if(time==20){
				setBackground(Color.RED);
			}
			else if(time==30){
				setBackground(Color.BLACK);
			}
			else if(time==40){
				time=0;
			}
			repaint();
			try {
				Thread.sleep(10);
			}catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}

}